/***************************************************************************
 *   Copyright (C) 2007 by Nicholas Robbins, David Murphy                  *
 *   nrrobbin@umcg.org, djmurphy@umcg.org                                  *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/
using namespace std;
#include <iostream>

#include "gurps.h"

gurps::gurps(QWidget* parent, Qt::WindowFlags fl)
: QMainWindow( parent, fl )//, Ui::Form
{
	setupUi(this);
	gurpsChar *sheet = new gurpsChar(/*"default"*/);
}

void gurps::on_spinST_valueChanged(int n)
{
	cout << "ST changed" << endl;
	sheet->setStrength(n);
	int p = statPointCalc(n);
	stp->setNum(p);
}

void gurps::on_spinDX_valueChanged(int n)
{
	cout << "DX changed" << endl;
	sheet->setDexterity(n);
	double tempSpeed = (double (n) + double (sheet->getStamina()))/4;
	sheet->setSpeed(tempSpeed);
	int p = statPointCalc(n);
	dxp->setNum(p);

}

void gurps::on_spinIQ_valueChanged(int n)
{
	cout << "IQ changed" << endl;
	sheet->setInteligence(n);
	int p = statPointCalc(n);
	iqp->setNum(p);

}

void gurps::on_spinHT_valueChanged(int n)
{
	cout << "HT changed" << endl;
	sheet->setStamina(n);
	int p = statPointCalc(n);
	htp->setNum(p);

}

void gurps::changeStat(QString a, int n)
{
	
	int p;

	if ( a == "st" )
	{
		p = statPointCalc(n);
	}
	else if ( a == "dx")
	{
		p = statPointCalc(n);
	}
	else if ( a == "iq" )
	{
		p = statPointCalc(n);
	}
	else if ( a == "ht" )
	{
		p = statPointCalc(n);
	}
}

int gurps::statPointCalc ( int n )
{
	int temp = n-10;
	int cost = 0;

	if ( temp > 0 )
	{
		if (temp <= 3)
			cost = temp*10;
		else if (temp <= 5)
			cost = (temp - 3)*15 + 30;
		else if (temp <= 7)
			cost = (temp - 5)*20 + 60;
		else
			cost = (temp - 7)*25 + 100;
	}
	else if ( temp < 0 )
	{
		temp = temp * -1;
		if (temp == 1)
			cost = -10;
		else if (temp == 2)
			cost = -15;
		else
			cost = (temp*10 - 10)*-1;
	}
	
	cout << cost << endl;
	return cost;
}

gurps::~gurps()
{
	delete sheet;
}

/*$SPECIALIZATION$*/


